<template>
  <div>
    <div>
      <el-button type="primary" @click="autoDeal">自动处理</el-button>
    </div>
    <div>
      <el-table :data="accountDealingList" align="center">
        <el-table-column label="用户名" prop="username"></el-table-column>
        <el-table-column label="密码" prop="password"></el-table-column>
        <el-table-column label="公司名称" prop="company_name"></el-table-column>
        <el-table-column label="操作" prop="operation"></el-table-column>
      </el-table>
    </div>
    <div>
      <el-table :data="macDealingList" align="center">
        <el-table-column label="MAC地址" prop="mac"></el-table-column>
        <el-table-column label="操作" prop="operation"></el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      accountDealingList: [],
      macDealingList: []
    };
  },
  created() {
    this.getDealingList();
  },
  methods: {
    getDealingList() {
      this.axios
        .get("/get_dealing")
        .then(response => {
          this.accountDealingList = response.data.accountinfos;
          this.macDealingList = response.data.macinfos;
        })
        .catch(error => {
          console.log(error);
        });
    },
    autoDeal() {
      const loading = this.$loading({
        lock: true,
        text: "VPN系统配置中",
        spinner: "el-icon-loading",
        background: "rgba(0,0,0,0.7)"
      });
      this.axios
        .get("/autodealing", { timeout: 600000 })
        .then(response => {
          if (response.data.success == 1) {
            loading.close();
            this.$alert("VPN系统自动加载成功", "加载成功", {
              confirmButtonText: "确定",
              callback: () => {
                this.$message({
                  type: "info",
                  message: "VPN系统已经生效！"
                });
              }
            });
          } else {
            loading.close();
            this.$message({
              message: "文件自动处理失败，请手动处理！",
              type: "warn"
            });
          }
        })
        .catch(error => {
          loading.close();
          console.log(error);
        });
    }
  }
};
</script>
